﻿//双击事件
function CustomDbClick() {
    parent.closeWin(); //去掉双击功能
}

//新增技能分类
var fnAddCategory = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请先选择上级分类！");
        return;
    }
    var CategoryName = _Caption;
    const_EditEntity = "DatSkillCategory";
    document.getElementById("dialog1_h").innerHTML = "新增技能分类";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&CategoryID=" + CategoryID + "&CategoryName=" + CategoryName + "&flag=Add";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    parent.NeedRefreshPage = this;
}

//保存成功回调
var CallBackParameter = function (obj) {
    //debugger;
    RefreshTreeData(obj.Category, obj.ID);
}

//修改技能分类
var fnEditCategory = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请先选择上级分类！");
        return;
    }
    var CategoryName = _Caption;
    const_EditEntity = "DatSkillCategory";
    document.getElementById("dialog1_h").innerHTML =CategoryName+  "_修改";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&CategoryID=" + CategoryID + "&CategoryName=" + CategoryName + "&flag=Edit";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//删除技能分类
var fnDelCategory = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请选择要删除的分类！");
        return;
    }
    var CategoryName = _Caption;
    const_EditEntity = "DatSkillCategory";

    if (confirm("删除后将无法恢复,确定要删除吗?")) {
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/DatPostAjax.aspx?flag=isdelskillcategory" + "&id=" + CategoryID, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        deleteNode();
                    }
                    else if (str == "2") {
                        alert("有下级分类，不能删除！");
                        return;
                    }
                    else if (str == "3") {
                        alert("有技能引用了分类，不能删除！");
                        return;
                    }
                    else if (str == "-1" || str == "0") {
                        alert("删除失败！");
                        return;
                    }
                }
                catch (e) {
                    alert("删除失败：" + e.Message);
                    return;
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
                return;
            }
        }, null);
    }
}

//新增技能
var fnCustomAdd = function () {
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请选择分类！");
        return;
    }
    var CategoryName = _Caption;

    const_EditEntity = "datSkill";
    var pagetitle = "新增技能";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&flag=add" + "&CategoryID=" + CategoryID + "&CategoryName=" + CategoryName));
    //parent.NeedRefreshPage = this;
}

//修改技能
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "datSkill";
    //debugger
    var pagetitle = "修改技能_" + record._oData["Caption"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&flag=edit" + "&id=" + record.getData(const_entityID)));
    //parent.NeedRefreshPage = this;

}

//删除技能
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        //this.getRecordSet()._records[0]._oData["BarItem"]
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }

    var id = record.getData(const_entityID);
    //第一步先删除相关的引用表信息、子表、主表
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/DatPostAjax.aspx?flag=deleteskill" + "&json=" + elist.join(","), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                        SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                        YAHOO.example.container.dialog3.show();
                    }  
                }
                else if (str == "0") {
                    alert("此技能已经被引用，不能删除！");
                    return;
                }
                else if (str == "-1") {
                    alert("此技能ID为空，删除失败！");
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}




